//@author A0088498A
package common;

import java.util.ArrayList;
 
/**
 * Supported commands <br/>
 * Define all the command keywords <br/>
 */

public enum CommandType {
	add,
	update,
	delete,
	display,
	search,
	undo,
	exit,
	confirm,
	mark,
	unmark,
	discard,
	block,
	unblock,
	clear,
	invalid;
	
	/**
	 * Convert the String into the CommandType
	 * 
	 * @param string
	 *            to be converted
	 * @return the CommandType converted. Return invalid if the string is null
	 *         or cannot be converted
	 */
	public static CommandType getValueOf(String string) {
		try {
			return valueOf(string);
		} catch (RuntimeException e) {
			return invalid;
		}
	}
	
	/**
	 * Search for the keyword with the prefix provided
	 * @param prefix
	 * @return a list of attribute type having the prefix
	 */
	public static ArrayList<String> searchKeyword(String prefix) {
		ArrayList<String> keywords = new ArrayList<String> ();
		
		CommandType[] commandTypes = CommandType.values();
		for (CommandType cmd : commandTypes) {
			String keyword = cmd.toString();
			if (keyword.startsWith(prefix)) {
				keywords.add(keyword);
			}
		}
		
		return keywords;
	}
}
